<?php
/**
 * @file 测试-> bg-top-json-procedure.php
 * @version 0.1
 * @desc 输出买入、卖出TOP值, 输出json, (使用MySQl存储过程)
 * 
DELIMITER //
DROP PROCEDURE IF EXISTS bus_top //
CREATE PROCEDURE bus_top()
	SELECT `price`, `num`, `flag` FROM `bus_top` ORDER BY `price` DESC;
 //
DELIMITER ;
 *
 */

	$msg = '';
	
	require_once ../function.php;
	$conn = &ADONewConnection('mysqli');
	$conn->debug = false;
	$conn->Connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
	if (!$conn){
		$msg = "MySQL Connect Failed!";
		die("Mysql 连接失败！");
	}
	$conn->Execute('SET NAMES UTF8');
	$ADODB_FETCH_MODE = ADODB_FETCH_ASdSOC;
	
	$top = array();
	$re= dbGetListByProcedure($conn, "CALL bus_top()");
	foreach($re as $t){
		array_push($top,array('price' => $t['price'],
								'num' => $t['num'],
								'flag' => $t['flag'])
		);
	}
	
	
	/*
	//卖出
	$re4 = dbGetListByProcedure($conn, "CALL bus_top(4)");
	$sell = array();
	foreach ($re4 as $sells){
		array_push($sell,array('price' => $sells['price'],
									'num' => $sells['num']));
	}
	
	//买入
	$re3 = dbGetListByProcedure($conn, "CALL bus_top(3)");
	$buy = array();
	foreach ($re3 as $buys){
		array_push($buy, array('price' => $buys['price'],
									'num' => $buys['num']));
	}*/
	
	
	$conn->Close();
	$result = array('top' => $top,
					'msg' => $msg );
	echo json_encode($result);
?>